home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MYMUD21.ZIP / MMUD21.ZIP / SOURCE / SOURCE.ZIP / MYMUD.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-01-21  |  14.8 KB  |  560 lines

  1. {$I COPYRGHT.INC}
  2. {$A+,B-,D+,E-,F-,I-,L+,N-,O-,R-,S+,V-}
  3. {$M 30000,0,0}
  4. {$DEFINE debug     }   {Turn on/off the debugging #REC and #FIX commands }
  5. { $DEFINE SimpleMode}  { Turn on the simple line editor }
  6.  
  7. Program MyMUD;
  8. Uses MyIO,
  9.      Misc,
  10.      Multi,
  11.      Header,
  12.      BoolExpr,
  13.      BIN_DB,
  14.      LowLevel,
  15.      Meta_Do,
  16.      Norm_do,
  17.      Macro,
  18. {$IfNDef SimpleMode}
  19.      NiceLine,
  20. {$EndIf}
  21.      Timer,
  22. {$IfDef Debug}
  23.      Debug_do,
  24. {$EndIf}
  25.      VerbList;
  26.  
  27.  
  28. Const PollTimeOut = 5; { Check for semafore and mail every x seconds }
  29.  
  30. Var Current     : ContextType;
  31.     Nr          : Integer;
  32.     Stop        : Boolean;
  33.     Command     : String;
  34.     Name        : String[20];
  35.     Prompt      : String[10];
  36.     ExitSave    : Pointer;
  37.     PrevRoom    : Integer;
  38.     MemStatus   : Byte;
  39.     AllOk       : Boolean;
  40.  
  41. Procedure Do_Short(Var Current : ContextType);
  42. Begin
  43. Current.DB.ReadObj(Current.Room);
  44. My_WriteLn(#13+HighLight+Current.DB.Name+LowLight);
  45. List_Things(Current.DB.ObjRec.Contents,False);
  46. List_Players(Current,Current.DB.ObjRec.Contents);
  47. End;
  48.  
  49. Procedure Do_ShowVersion;
  50. Begin
  51. My_WriteLn('');
  52. My_WriteLn(MudName+' '+MudVersion+' compiled at '+CompileDate);
  53. My_WriteLn('Original code written by Gerhard Hoogterp,');
  54. My_WriteLn('  Fidonet: 2:283/7.33 or 2:282/100.5');
  55. My_WriteLn('  Internet: Gerhard@Loipon.wlink.nl');
  56. My_WriteLn('');
  57. End;
  58.  
  59. Procedure ResetCurrent(Var Current : ContextType);
  60. Begin
  61. Current.DB.ReadObj(Current.Player);
  62. Current.Room:=Current.DB.ObjRec.Location;
  63. Current.Level:=Current.DB.ObjRec.ObjLevel;
  64. Current.Gender:=Current.DB.WhichGender;
  65. Current.PlayerName:=Current.DB.Name;
  66.  
  67. Multi.UpdateNodeInfo(Current);
  68. Prompt:=Current.PlayerName+'> ';
  69. End;
  70.  
  71. (*-------------------------------------------*)
  72.  
  73. (*-------------------------------------------*)
  74.  
  75. Procedure DoCommand(Var Current : ContextType;InpStr : String);
  76. Var Command : String;
  77.     Comm_T  : VerbTypes;
  78.     Count   : Byte;
  79.     Home    : String;
  80.     Tmp     : Byte;
  81.     SpacePos: Byte;
  82.     Key     : Char;
  83.  
  84. Begin
  85. { Tabs -> Spaces }
  86. For Tmp:=1 To Length(InpStr) Do
  87.  If InpStr[Tmp]=#9
  88.     Then InpStr[Tmp]:=' ';
  89.  
  90. { Remove leading and trailing spaces }
  91. While (InpStr<>'') and (InpStr[1]=' ') Do Delete(InpStr,1,1);
  92. While (InpStr<>'') And (InpStr[Length(InpStr)]=' ') Do Dec(InpStr[0]);
  93.  
  94. If InpStr=''
  95.    Then Begin
  96.         Do_Short(Current);
  97.         Exit;
  98.         End;
  99.  
  100. { Remove double spaces }
  101.  
  102. Repeat
  103.  SpacePos:=Pos('  ',InpStr);
  104.  If SpacePos>0
  105.     Then Delete(InpStr,SpacePos,1);
  106. Until SpacePos=0;
  107.  
  108. { Translate variables! }
  109.  
  110. Current.DB.ReadObj(Current.Player);
  111. For Count:=0 To 9 Do
  112.  Begin
  113.  Tmp:=Pos('&'+Nr2Str(Count),InpStr);
  114.  If Tmp>0
  115.     Then Begin
  116.          Delete(InpStr,Tmp,2);
  117.          Insert(Nr2Str(Current.DB.ObjRec.Storage[Count]),InpStr,Tmp);
  118.          End;
  119.  End;
  120.  
  121.  
  122.  
  123.  
  124. { Token support }
  125.  
  126. If InpStr[1]=SAY_TOKEN
  127.    Then Begin
  128.         Do_Say(Current,InpStr);
  129.         Exit;
  130.         End;
  131.  
  132. If InpStr[1]=POSE_TOKEN
  133.    Then Begin
  134.         Delete(InpStr,1,1);
  135.         SayToAllHere(Current,' '+InpStr);
  136.         My_WriteLn(Current.PlayerName+' '+InpStr);
  137.         Exit;
  138.         End;
  139.  
  140. If InpStr[1]=WHISPER_TOKEN
  141.    Then Begin
  142.         Delete(InpStr,1,1);
  143.         InpStr:='WHISPER '+InpStr;
  144.         End;
  145.  
  146. If InpStr[1]=USE_TOKEN
  147.    Then Begin
  148.         Delete(InpStr,1,1);
  149.         InpStr:='USE '+InpStr;
  150.         End;
  151.  
  152. If can_move(Current,InpStr)
  153.    Then Begin
  154.         do_Move(Current);
  155.         Do_Short(Current);
  156.         Exit;
  157.         End;
  158.  
  159. If HandledMoveFail  { An acceptable movement, but not accepted }
  160.    Then Exit;
  161.  
  162. SpacePos:=1;
  163. Command:='';
  164. While (SpacePos<=Length(InpStr)) and (InpStr[SpacePos]<>' ') Do
  165.  Begin
  166.  Command:=Command+Upcase(InpStr[SpacePos]);
  167.  Inc(SpacePos);
  168.  End;
  169. Delete(InpStr,1,SpacePos);
  170.  
  171. If Not InMacro
  172.    Then Comm_T:=Verb2Key(Command,Current.Level)
  173.    Else Comm_T:=Verb2Key(Command,Wizard_Level);
  174.  
  175. Case Comm_T of     { the normal commands }
  176.    Help_T       : ShowHelp(Current.Level);
  177.    LHelp_T      : Do_Help(InpStr);
  178.    Look_T       : Begin
  179.                   If Not Do_Look_at(Current,InpStr)
  180.                      Then My_WriteLn('There is no '+InpStr+' here.');
  181.                   End;
  182.    Exam_T       : Do_Examine(Current,InpStr);
  183.    Goto_T       : Begin
  184.                   If Can_Move(Current,InpStr)
  185.                      Then Begin
  186.                           do_Move(Current);
  187.                           Do_Short(Current);
  188.                           End;
  189.                   End;
  190.    Home_T       : Begin
  191.                   Do_Go_Home(Current,True);
  192.                   Do_Short(Current);
  193.                   End;
  194.    Inv_T        : Do_Inventory(Current);
  195.    Say_T        : Do_Say(Current,InpStr);
  196.    Rob_T        : Do_Rob(Current,InpStr);
  197.    Score_T      : Do_Score(Current);
  198.    Get_T        : Do_Get(Current,InpStr);
  199.    Drop_T       : Do_Drop(Current,InpStr);
  200.    Quit_T       : Stop:=True;
  201.    News_T       : Begin
  202.                   If ExistFile(TextPath+'NEWS.MUD')
  203.                      Then ShowFile(TextPath+'NEWS.MUD')
  204.                      Else ShowFile(HomeDir+'NEWS.MUD');
  205.                   End;
  206.    Kill_T       : Do_Kill(Current,InpStr);
  207.  
  208.    WhoOn_T      : Do_WhosOn;
  209.    Version_T    : Do_ShowVersion;
  210.    Give_T       : Do_Give(Current,InpStr);
  211.    Whisper_T    : Do_Whisper(Current,InpStr);
  212.    Time_T       : My_WriteLn('Local time here is '+TimeStamp);
  213.    Page_T       : Do_Page(Current,InpStr);
  214.    Use_T        : Do_Use(Current,InpStr);
  215.  
  216. { The meta commands }
  217.  
  218.    RaiseLev_M   : Meta_Change_Level(Current,InpStr,1);
  219.    LowerLev_M   : Meta_Change_Level(Current,InpStr,-1);
  220.  
  221.    SetFlag_M    : Meta_SetFlag(Current,InpStr);
  222.    WNews_T      : Begin
  223.                   If ExistFile(TextPath+'WNEWS.MUD')
  224.                      Then ShowFile(TextPath+'WNEWS.MUD')
  225.                      Else ShowFile(HomeDir+'WNEWS.MUD');
  226.                   End;
  227.    Stats_M      : ShowLockStat;
  228.    ShoutAll_M   : SayToAll('A voice boomes out of nowhere and says:'#13#10'  "'+InpStr+'"');
  229.    Create_M     : Meta_CreateObj(Current,InpStr);
  230.    Chown_M      : Meta_Chown(Current,InpStr);
  231.    ChangeName_M : Meta_ChangeName(Current,InpStr);
  232.    ShutDown_M   : Begin
  233.                   SayToAll('The Game is going to shut down!');
  234.                   My_Delay(3000);
  235.                   ShutDownGame;
  236.                   Halt(99);
  237.                   End;
  238.    SetLock_M    : Meta_Set_Lock(Current,InpStr);
  239.    Unlock_M     : Meta_Unlock(Current,InpStr);
  240.    SetHome_M    : Meta_HomeHere(Current,InpStr);
  241.    Home_M       : Meta_ChangeHome(Current,InpStr);
  242.    Desc_M       : Meta_Make_Text(Current,InpStr,0);
  243.    Finger_M     : Meta_Finger(Current,InpStr);
  244.    Destroy_M    : {Meta_Destroy(Current,InpStr)} My_WriteLn('Nothing happens');
  245.  
  246.    Fail_M       : Meta_Make_Text(Current,InpStr,1);
  247.    OFail_M      : Meta_Make_Text(Current,InpStr,3);
  248.  
  249.    Success_M    : Meta_Make_Text(Current,InpStr,2);
  250.    OSuccess_M   : Meta_Make_Text(Current,InpStr,4);
  251.    Macro_M      : Meta_Make_Text(Current,InpStr,5);
  252.  
  253.    Info_M       : Begin
  254.                   If Current.Level>Builder_Level
  255.                      Then Meta_Make_Text(Current,InpStr,6)
  256.                      Else Meta_Make_Text(Current,'ME',6);
  257.                   End;
  258.  
  259.    ChangePass_M : Meta_ChangePassword(Current,InpStr);
  260.    Note_M       : Current.Note:=CleanUp(InpStr);
  261.  
  262.    Dig_M        : Meta_Dig(Current,InpStr);
  263.    Open_M       : Meta_OpenLink(Current,InpStr);
  264.    Action_M     : Meta_Action(Current,InpStr);
  265.    Find_M       : Meta_Find(Current,InpStr);
  266.    Teleport_M   : Meta_Teleport(Current,InpStr);
  267.    Edit_M       : Meta_Edit(Current,InpStr);
  268.  
  269. {$IfDef debug}
  270.    ShowRec_D    : DEBUG_ShowRecord(Current,InpStr);
  271.    Fix_D        : Debug_Fix(Current,InpStr);
  272. {$EndIf}
  273.  
  274.    Wait_At_At   : ;
  275.  Else           Begin
  276.                 If InMacro
  277.                    Then Begin
  278.                         Case Comm_T Of
  279.                           Set_Mc    : Macro_Let(Current,InpStr);
  280.                           Random_Mc : Macro_Random(Current,InpStr);
  281.                           Show_MC   : Macro_ShowFile(Current,InpStr);
  282.                           Say_MC    : Macro_SayUser(Current,InpStr);
  283.                           SayAll_MC : Macro_SayAll(Current,InpStr);
  284.                           Pennies_MC: Macro_Pennies(Current,InpStr);
  285.                           IF_Mc     : ;
  286.                         End; {Case}
  287.                         End
  288.                    Else My_WriteLn('Euh?');
  289.                 End;
  290. End; {Case command}
  291. End;
  292.  
  293. {$IfDef SimpleMode}
  294. Function ReadLine(Var Current : ContextType;Prompt : String):String;
  295. Var EOline : Boolean;
  296.     Key    : Char;
  297.     Line   : String;
  298.     Timer  : TimerObject;
  299.     Count  : Byte;
  300. Begin
  301.  
  302. Timer.SetTimer(PollTimeOut*10);
  303.  
  304. My_Write(HighLight+Prompt);
  305. Line:='';
  306. EoLine:=False;
  307. Count:=0;
  308. Repeat
  309.  If My_KeyPressed
  310.     Then Begin
  311.          Key:=My_ReadKey;
  312.          Case Key Of
  313.           #0 : Key:=My_ReadKey;
  314.           #27: Begin
  315.                While Line<>'' DO
  316.                 Begin
  317.                 My_Write(#8' '#8);
  318.                 Dec(Line[0]);
  319.                 End;
  320.                End;
  321.           #8 : Begin
  322.                If Line<>''
  323.                   Then Begin
  324.                        Dec(Line[0]);
  325.                        My_Write(#8' '#8);
  326.                        End;
  327.                End;
  328.           #13: EoLine:=True;
  329.          Else  Begin
  330.                If Key>=' '
  331.                   Then Begin
  332.                        Line:=Line+Key;
  333.                        My_Write(Key);
  334.                        End
  335.                   Else My_Write(#7);
  336.                End;
  337.          End; {Case}
  338.          End;
  339.  
  340. If Timer.TimeUp
  341.    Then Begin
  342.         If CheckShutDown
  343.            Then Begin
  344.                 My_WriteLn('');
  345.                 My_WriteLn(' *** The game has been shut down!');
  346.                 Halt;
  347.                 End;
  348.         If CheckMail
  349.            Then Begin
  350.                 My_Write(#13);
  351.                 My_ClrEol;
  352.                 My_Write(LowLight);
  353.                 ReadMail;
  354.                 My_Write(HighLight+Prompt+Line);
  355.                 End;
  356.         If CheckResetMe
  357.            Then Begin
  358.                 My_WriteLn('');
  359.                 ReadLine:='';
  360.                 Exit;
  361.                 End;
  362.         Timer.SetTimer(15);
  363.         End;
  364. Until EoLine;
  365.  
  366. My_WriteLn(LowLight);
  367. My_WriteLn('');
  368. ReadLine:=Line;
  369. End;
  370. {$Else}
  371. Function ReadLine(Var Current : ContextType;Prompt : String):String;
  372. Var EoLine : Boolean;
  373.     Line   : String;
  374.     Count  : Byte;
  375.  
  376. Begin
  377. EoLine:=False;
  378. Line:='';
  379. Count:=0;
  380. Repeat
  381.   Case LineEditor(HighLight+Prompt,Line,70,PollTimeOut*10) Of
  382.     Ready_Status   : Begin
  383.                      ReadLine:=Line;
  384.                      EoLine:=True;
  385.                      End;
  386.     TimeOut_Status : Begin
  387.                      My_Write(LowLight);
  388.                      If CheckShutDown
  389.                         Then Begin
  390.                              My_WriteLn('');
  391.                              My_WriteLn(' *** The game has been shut down!');
  392.                              Halt;
  393.                              End;
  394.                      If CheckMail
  395.                         Then Begin
  396.                              My_Write(#13);
  397.                              My_ClrEol;
  398.                              My_Write(LowLight);
  399.                              Lock('ReadMail');
  400.                              ReadMail;
  401.                              UnLock;
  402.                              My_Write(HighLight+Prompt+Line);
  403.                              End;
  404.                      If CheckResetMe
  405.                         Then Begin
  406.                              My_WriteLn('');
  407.                              ReadLine:='';
  408.                              Exit;
  409.                              End;
  410.                      My_Write(HighLight);
  411.                      End;
  412.   End;
  413. Until EoLine;
  414. My_WriteLn(LowLight);
  415. End;
  416.  
  417.  
  418. {$EndIf}
  419.  
  420. {$F+}
  421. Procedure MudExit;
  422. {$F-}
  423. Begin
  424. ExitProc:=ExitSave;
  425. If IoResult<>0
  426.    Then;
  427. If ExitCode=0
  428.    Then Exit;
  429. If ExitCode=1
  430.    Then My_ClrScr;
  431. My_WriteLn('See you again some other time..');
  432. If ExitCode>1
  433.    Then Begin
  434.         My_WriteLn('ExitCode: '+Nr2Str(ExitCode));
  435.         Current.DB.Final;
  436.         End;
  437.  
  438. Multi.FreeNode;
  439. Current.Player:=NOTHING;
  440. Multi.UpdateNodeInfo(Current);
  441. End;
  442.  
  443. Function GrabCommand(Var Macro : String):String;
  444. Var Tmp  : String;
  445.     MPtr : Byte;
  446. Begin
  447. Tmp:='';
  448. MPtr:=1;
  449. While (Macro[MPtr]<>'^') and (MPtr<=Length(Macro)) Do
  450.  Begin
  451.  Tmp:=Tmp+Macro[MPtr];
  452.  Inc(MPtr);
  453.  End;
  454. Delete(Macro,1,MPtr);
  455. GrabCommand:=Tmp;
  456. End;
  457.  
  458.  
  459.  
  460.  
  461. Begin
  462. ExitSave:=ExitProc;
  463. ExitProc:=@MudExit;
  464. Randomize;
  465.  
  466. My_ClrScr;
  467. Multi.ReadINI;
  468. Multi.GrabNodeNr;
  469.  
  470. Current.DB.Init;
  471. Repeat
  472.   AllOk:=False;
  473.   Case LogIn(Current) of
  474.    NormalLogin : AllOk:=True;
  475.    NewLogin    : Begin
  476.                  My_WriteLn('Yeah! A newbie!');
  477.                  AllOk:=True;
  478.                  End;
  479.    AskedQuit   : Begin
  480.                  Current.DB.Final;
  481.                  Halt(1);
  482.                  End;
  483.    ShowVersion : Begin
  484.                  My_ClrScr;
  485.                  Do_ShowVersion;
  486.                  My_WaitForKey('─── Press a key ───');
  487.                  End;
  488.    ShowWho     : Begin
  489.                  My_ClrScr;
  490.                  Do_WhosOn;
  491.                  My_WaitForKey('─── Press a key ───');
  492.                  End;
  493.   End; {case}
  494. Until AllOk;
  495.  
  496. If Current.Player=NOTHING
  497.    Then Halt;
  498. ResetCurrent(Current);
  499.  
  500. Stop:=False;
  501. My_ClrScr;
  502. My_WriteLn('');
  503. My_WriteLn(HighLight+'Welcome at '+MudName+' '+MudVersion+' ('+CompileDate+')');
  504. My_WriteLn(Current.PlayerName+', you''re on node '+Nr2Str(MyNode)+LowLight);
  505. My_WriteLn('');
  506.  
  507. Current.Db.ReadObj(Current.Player);
  508.  
  509. Do_Short(Current);
  510. If Not Current.DB.IsInvisible
  511.    Then SayToAllHere(Current,' appears out of nowhere..');
  512.  
  513. PrevRoom:=Current.Room;
  514. Current.DB.Final;
  515. MacroString:='';
  516. MemStatus:=Current.Level;
  517. Repeat
  518.  Current.Level:=MemStatus;
  519.  Current.DB.Init;
  520.  
  521.  Generate_Pennies(Current);
  522.  InMacro:=False;
  523.  If MacroString=''
  524.     Then Command:=ReadLine(Current,Current.PlayerName+'> ')
  525.     Else Begin
  526.          InMacro:=True;
  527.          Command:=GrabCommand(MacroString);
  528.          End;
  529.  
  530.  LastSentence:=Command;
  531.  ResetCurrent(Current);
  532.  DoCommand(Current,Command);
  533.  Multi.UpdateNodeInfo(Current);
  534.  If (PrevRoom<>Current.Room) And
  535.     (Not Current.DB.IsInvisible)
  536.     Then Begin
  537.          SayToAllHere(Current,' arrives.');
  538.          PrevRoom:=Current.Room;
  539.          End;
  540.  
  541.  If Stop
  542.     Then Begin
  543.          Current.Db.ReadObj(Current.Player);
  544.          If Not Current.DB.IsInvisible
  545.             Then SayToAllHere(Current,' goes home..');
  546.          If Not Current.DB.IsSticky
  547.             Then Do_Go_Home(Current,False);
  548.          End;
  549.  
  550.  Current.DB.Final;
  551.  {$IfDef Debug}
  552.   If LockLevel<>0
  553.      Then My_WriteLn('DEBUG: LockLevel>0');  { LockLevel should always be 0 after a processed command }
  554.  {$EndIf}
  555. Until Stop;
  556. Halt(1);
  557. End.
  558.  
  559.  
  560.